<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title></title>
	</head>
	<body>

		<script type="text/javascript">
			// 声明一个函数，输入一个整数n, 返回 1!+2!+3!+4!+…n!，另外再使用1个函数封装n!。
			let num = window.prompt("请输入n");
			function js(num) {
				let sum = 0;
				for (let i = 1; i <= num; i++) {
					let factorial = 1; //1! = 1		阶乘
					for (let j = 1; j <= i; j++) {
						factorial = factorial * j; //或者写成factorial *= j
					}
					sum += factorial;
				}
				console.log("1到" +  num + "阶乘的和为：" + sum)
			}
			
			function n(num) {
				if (num < 2) {
					return 1;
				} else {
					return num * n(num - 1);
				}
			}
			js(num);
			console.log(num +'的阶乘为：' + n(num));
		</script>
	</body>
</html>
